from DBA.dbmanager import DBInterface

class PerfWifi:
	def __init__(self):
		self.id			= {"key":"ID","value":""}
		self.ensPerf		= []
		self.__interfacebase	= DBInterface()
		self.id["value"]	= str(self.__interfacebase.createNewID());
	
	def createByListeDico(self,liste):
	    for perf in liste:
		pe = Perf()
		pe.createByDico(perf)
		self.addPerf(pe)

	def addPerf(self,perf):
		self.ensPerf.append(perf)
	
	def nbPerfs(self):
		return self.ensPerf.count()
	
	def insertToDb(self,idMesure):
		inter   = self.createPerfDico(idMesure)
		self.__interfacebase.insert(self.__interfacebase.ref_iperf_mesuretablename,self.__interfacebase.ref_iperf_mesuremapping,inter)
		for perf in self.ensPerf:
			perf.insertToDb(self.id["value"])

	def updateIntoDb(self,idMesure):
		inter   = self.createPerfDico(idMesure)
		self.__interfacebase.update(self.__interfacebase.ref_iperf_mesuretablename,self.__interfacebase.ref_iperf_mesuremapping,inter)
		for perf in self.ensPerf:
			perf.updateIntoDb(self.id["value"])
	
	def createPerfDico(self,idMesure):
		dico ={}
		dico[self.id["key"]]		= self.id["value"]
		dico["link_me"]			= idMesure
		return dico

class Perf:	
	def __init__(self):
		self.id			= {"key":"ID","value":""}
		self.bandePassante	= {"key":"bande_passante","value":""}
		self.intervalle		= {"key":"intervalles","value":""}
		self.transfere		= {"key":"transfere","value":""}
		self.__interfacebase	= DBInterface()
		self.id["value"]	= str(self.__interfacebase.createNewID());
	
	def createByDico(self,dico):
		self.bandePassante["value"]	= dico[self.bandePassante["key"]]
		self.intervalle["value"]	= dico[self.intervalle["key"]] 
		self.transfere["value"]		= dico[self.transfere["key"]]

	def insertToDb(self,idPerf):
		dico 	= self.createConfigPerfDico(idPerf)
		self.__interfacebase.insert(self.__interfacebase.iperftablename,self.__interfacebase.iperfmapping,dico)
	
	def createConfigPerfDico(self,idPerf):
		dico ={}
		dico[self.id["key"]]		= idPerf
		dico[self.bandePassante["key"]]	= self.bandePassante["value"]
		dico[self.intervalle["key"]]	= self.intervalle["value"]
		dico[self.transfere["key"]]	= self.transfere["value"]
		return dico
	
